# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_webadmin_session_id'
  
  def exclusion(modelo, excluidos)
		excluidos.each do |excluido|
			for column in modelo.content_columns
				if column.name == excluido 
					 modelo.content_columns.delete column
				end 
			end
		end
	end
	
	def cambio_de_nombre(modelo, victimas)
		llaves = victimas.keys
		llaves.each do |llave|
			for column in modelo.content_columns
				if column.name == llave
					column.name = victimas[llave]
				end
			end
		end
	end
	
private 

  def authorize_admin 
    unless 'admin' == session[:username]
      flash[:notice] = "Para realizar esa acción debes ser administrador" 
      redirect_to(:controller => "app", :action => "login") 
    end 
  end 
  
  def authorize_user
    unless Alumno.find_by_username(session[:username]) || Profesor.find_by_username(session[:username]) 
      flash[:notice] = "Por favor inicia sesión" 
      redirect_to(:controller => "app", :action => "login") 
    end 
  end 
	
end
